<?php
namespace app\admin\controller;
use think\Request;
use app\common\controller\Backend;
use app\common\model\UserModel;

class User extends Backend
{
	//列表页面
  public function index(Request $request = null)
  {
    $UserModel = new UserModel();
    $list = $UserModel->getUserList($request->get());

  	return view("index",['list'=>$list]);
  }

  //用户详情页
  public function detail(Request $request = null){
    $id = $request->param("id");

    //获取用户详情
    $UserModel = new UserModel();
    $userInfo = $UserModel->getUserById($id);
    // dump( $userInfo );die();

    return view("detail",['userInfo'=>$userInfo]);
  }


  //改变用户状态
  public function changeStatus(){
    $status = Request::instance()->post("status");
    $ids = $_POST['id'];
    if(!is_array($ids)){return json(['status'=>400,'msg'=>'id不符合格式！']);}
    $UserModel = new UserModel();
    if($UserModel->changeStatus($ids, $status) > 0){
      return json(['status'=>200,'msg'=>'成功']);
    }else{
      return json(['status'=>400,'msg'=>'失败']);
    }
  }
}
